# @Version        : 1.0
# @Update Time    : 2024/11/24 15:32
# @File           : task_model.py
# @IDE            : PyCharm
# @Desc           : 定时任务模型
import datetime

from advanced_alchemy.base import BigIntAuditBase
from sqlalchemy import String, Boolean, DateTime
from sqlalchemy.orm import Mapped, mapped_column
# from src.common.typing.schema_typing import DictStr, DatetimeStr


class SysTask(BigIntAuditBase):
    """
    定时任务模型
    """

    __tablename__ = "sys_task"
    __table_args__ = {"comment": "定时任务表"}

    name: Mapped[str] = mapped_column(String(50), nullable=False, comment="任务名称")
    group: Mapped[str | None] = mapped_column(
        String(50), nullable=True, comment="任务分组'memory' or 'redis'"
    )
    job_class: Mapped[str] = mapped_column(
        String(255), nullable=False, comment="任务执行实体类"
    )
    job_params: Mapped[str] = mapped_column(
        String(255),
        default="{}",
        nullable=False,
        comment="任务执行实体类参数, dict 类型参数, 入参方式为：**kwargs",
    )
    exec_strategy: Mapped[str] = mapped_column(
        String(50), nullable=False, comment="执行策略"
    )
    expression: Mapped[str | None] = mapped_column(
        String(50), nullable=True, comment="执行表达式, 一次任务可以不填"
    )
    is_active: Mapped[bool] = mapped_column(
        Boolean, nullable=False, comment="状态是否正常"
    )
    remark: Mapped[str | None] = mapped_column(
        String(255), nullable=True, comment="描述"
    )
    start_datetime: Mapped[datetime.datetime | None] = mapped_column(
        DateTime, nullable=True, comment="任务开始时间"
    )
    end_datetime: Mapped[datetime.datetime | None] = mapped_column(
        DateTime, nullable=True, comment="任务结束时间"
    )
